<?php
namespace Admin\Controller;
use Think\Controller;
class AdCheckController extends Controller {
    public function adCheck(){
        //$type=$_GET['type'];
        isMyCookie();
        isLogin();
        
        $flag= $_GET['flag'];
        
        $Ad=M("advertising");
        //$field=$Info->getInfoField();
        $field = "id,title,content,fdate,CASE flag
           WHEN '1' THEN '已推荐'
           WHEN '0' THEN '未推荐'
        END as flag";
        //$map['type']=array('eq',$type);
        $state['flag']=array('eq',$flag);
        
        if($flag==1||$flag==0){
            $count = $Ad->where($state)->count();
        }else {
            $count = $Ad->count();
        }
        
        $Page=getMyPage($count,10);
        $show       = $Page->show();
        
        if($flag==1||$flag==0){
            $list  = $Ad->field($field)->where($state)->order('fdate desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        }else {
            $list  = $Ad->field($field)->order('fdate desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        }
        
        $this->assign("list", $list);
        $this->assign("page", $show);
        //var_dump($list);exit();
        
            
            if (count($list)>0){
               $this->display("Admin/ad");
            }else{
                $this->assign("msg","对不起没有查询到您要的信息!!!");
                $this->display("Admin/msg");
            }
    }
}